<<<<<<< HEAD
package com.wwx.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.wwx.dao.UserDao;
import com.wwx.entity.UserDO;
import com.wwx.util.JDBC;

public class UserDaoImpl implements UserDao{
	/**
	 * username 	账号
	 * password 	密码
	 * 	检查密码和账号是否存在
	 */
	public UserDO checkUserByPasswordAndUsername(String username, String password) {
		Configuration cfg=JDBC.getConfiguration();
		SessionFactory sessionFactory=cfg.buildSessionFactory();
		Session session=sessionFactory.openSession();
		String hql="from UserDO as a where a.username='"+username+"' and a.password='"+password+"'";
		Query query=session.createQuery(hql);
		UserDO user=(UserDO) query.uniqueResult();
		session.close();
		return user;
	}
	/**
	 * user 一个用户
	 * 添加用户
	 */
	public Integer addUser(UserDO user) {
		// TODO Auto-generated method stub
		Configuration cfg=JDBC.getConfiguration();
		SessionFactory sessionFactory=cfg.buildSessionFactory();
		Session session=sessionFactory.openSession();
		session.beginTransaction();
		Integer id=(Integer) session.save(user);
		session.getTransaction().commit();
		session.close();
		return id;
	}

	
}
=======
package com.wwx.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.wwx.dao.UserDao;
import com.wwx.entity.UserDO;
import com.wwx.util.JDBC;

public class UserDaoImpl implements UserDao{
	/**
	 * username 	账号
	 * password 	密码
	 * 	检查密码和账号是否存在
	 */
	public UserDO checkUserByPasswordAndUsername(String username, String password) {
		Configuration cfg=JDBC.getConfiguration();
		SessionFactory sessionFactory=cfg.buildSessionFactory();
		Session session=sessionFactory.openSession();
		String hql="from UserDO as a where a.username=:userName and a.password=:passWord";
		Query query=session.createQuery(hql);
		UserDO user=(UserDO) query.setString("userName", username).setString("passWord", password).uniqueResult();
		session.close();
		return user;
	}
	/**
	 * user 一个用户
	 * 添加用户
	 */
	public Integer addUser(UserDO user) {
		// TODO Auto-generated method stub
		Configuration cfg=JDBC.getConfiguration();
		SessionFactory sessionFactory=cfg.buildSessionFactory();
		Session session=sessionFactory.openSession();
		session.beginTransaction();
		Integer id=(Integer) session.save(user);
		session.getTransaction().commit();
		session.close();
		return id;
	}

	
}
>>>>>>> dev
